/**
 * 事故上报审核记录 编辑页
 *
 * 作者 admin
 * 日期 2024-08-07 16:24:25
 */
layui.use(['jquery','febs', 'form', 'validate'], function () {
    var $ = layui.$,
        febs = layui.febs,
        layer = layui.layer,
        form = layui.form,
        $view = $('#accidentAuditRecord-edit'),
        validate = layui.validate;

    form.verify(validate);
    form.render();
    initFormValue();

    function initFormValue() {
        if (accidentAuditRecordData) {
            form.val("accidentAuditRecord-edit-form", {
                "auditRecordId": accidentAuditRecordData.auditRecordId,
                "tenantId": accidentAuditRecordData.tenantId,
                "reportId": accidentAuditRecordData.reportId,
                "auditBusiness": accidentAuditRecordData.auditBusiness,
                "auditUserId": accidentAuditRecordData.auditUserId,
                "auditRealName": accidentAuditRecordData.auditRealName,
                "auditResult": accidentAuditRecordData.auditResult,
                "auditTime": accidentAuditRecordData.auditTime,
                "auditReason": accidentAuditRecordData.auditReason,
            });
        }
    }

    form.on('submit(accidentAuditRecord-edit-form-submit)', function (data) {
        addOrUpdate(data.field);
        return false;
    });

    function addOrUpdate(data) {
        if (data.auditRecordId && data.auditRecordId.length > 0) {
            febs.postArray(ctx + 'accidentAuditRecord/update', data, function () {
                layer.closeAll();
                febs.alert.success('修改成功');
                febs.reloadPage();
            });
        } else {
            febs.postArray(ctx + 'accidentAuditRecord', data, function () {
                layer.closeAll();
                febs.alert.success('新增成功');
                $('#febs-accidentAuditRecord').find('#query').trigger('click');
            });
        }
    }
});